package com.dailyblue.java.thread;

import lombok.SneakyThrows;

// 后台线程
public class DemoG {

    static class G1 extends Thread {
        @SneakyThrows
        public void run() {
            while (true) {
                System.out.println("g1");
                Thread.sleep(1000);
            }
        }
    }

    static class G2 extends Thread {
        @SneakyThrows
        public void run() {
            for (int i = 0; i < 10; i++) {
                System.out.println("g2");
                Thread.sleep(1000);
            }
        }
    }

    public static void main(String[] args) {
        G1 g1 = new G1();
        G2 g2 = new G2();
        // 当前线程设置为后台(守护)线程
        g1.setDaemon(true);
        g1.start();
        g2.start();
    }
}
